package com.atguigu.day08;

import org.apache.flink.contrib.streaming.state.EmbeddedRocksDBStateBackend;
import org.apache.flink.contrib.streaming.state.RocksDBStateBackend;
import org.apache.flink.runtime.state.filesystem.FsStateBackend;
import org.apache.flink.runtime.state.hashmap.HashMapStateBackend;
import org.apache.flink.runtime.state.memory.MemoryStateBackend;
import org.apache.flink.runtime.state.storage.FileSystemCheckpointStorage;
import org.apache.flink.runtime.state.storage.JobManagerCheckpointStorage;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;

import java.io.IOException;

public class Flink01_StateBackend {
    public static void main(String[] args) throws IOException {
        //1.获取到执行环境
        StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();

        //TODO 2.设置状态后端
        //老版本(1.13之前)
        //内存级别状态后端
        env.setStateBackend(new MemoryStateBackend());

        //文件系统级别
        env.setStateBackend(new FsStateBackend("hdfs://hadoop102:8020/checkpoint/....."));

        //RocksDB
        env.setStateBackend(new RocksDBStateBackend("hdfs://hadoop102:8020/checkpoint/....."));


        //新版本（1.13之后）
        //内存级别
        //本地状态存在TaskManager内存
        env.setStateBackend(new HashMapStateBackend());
        //CheckPoint状态
        env.getCheckpointConfig().setCheckpointStorage(new JobManagerCheckpointStorage());

        //文件系统级别
        env.setStateBackend(new HashMapStateBackend());
        //CheckPoint状态
        env.getCheckpointConfig().setCheckpointStorage(new FileSystemCheckpointStorage("hdfs://hadoop102:8020/checkpoint/....."));
        //或者 但是下面这种写法不能设置额外的参数
        env.getCheckpointConfig().setCheckpointStorage("hdfs://hadoop102:8020/checkpoint/.....");

        //RocksDB
        //本地状态
        env.setStateBackend(new EmbeddedRocksDBStateBackend());
        //CheckPoint状态
        env.getCheckpointConfig().setCheckpointStorage(new FileSystemCheckpointStorage("hdfs://hadoop102:8020/checkpoint/....."));
        //或者 但是下面这种写法不能设置额外的参数
        env.getCheckpointConfig().setCheckpointStorage("hdfs://hadoop102:8020/checkpoint/.....");



    }
}
